//
//  PaperFavoriteViewManager.m
//  ZYOnlineSchool
//
//  Created by 毕武侠 on 2017/3/3.
//  Copyright © 2017年 bwx. All rights reserved.
//

#import "PaperFavoriteViewManager.h"
#import "PaperAnswerModel.h"
#import "PaperFavoriteModel.h"

@interface PaperFavoriteViewManager ()

@property (nonatomic, strong) NSArray *urls;

@property (nonatomic, strong) PaperAnswerModel *model;

@end

@implementation PaperFavoriteViewManager
@dynamic model;


- (void)setupConfigure {
    
    [super setupConfigure];
    
    self.urls = @[@"Apifavorite/favorite_ques", @"Apifavorite/delete_favorite_ques"];
    self.rmodel = @"PaperFavoriteModel";
    [self setupLoadingView:self.superView];
    
    [self.receiveSignal subscribeNext:^(id x) {
        if ([x isKindOfClass:[PaperFavoriteModel class]]) {
            PaperFavoriteModel *favoriteModel = x;
            self.model.is_favorites = favoriteModel.is_favorites;
            NSString *msg = [NSString stringWithFormat:@"%@成功",favoriteModel.is_favorites ? @"收藏" : @"取消收藏"];
            [MBProgressHUD showTextOnly:kKeyWindow message:msg];
        }
    }];
}

- (void)setFavoriteSignal:(RACSignal *)favoriteSignal {
    _favoriteSignal = favoriteSignal;

    [_favoriteSignal subscribeNext:^(id x) {
        self.model = x;
        NSUInteger is_favorite = self.model.is_favorites;
        self.url = self.urls[is_favorite];

//        NSDictionary *params = @{@"ques_id"   : self.model.ques_id ? : @"",
//                                 @"ques_type" : self.model.ques_type ? : self.ques_type ? : @""};
//        [self loadDataWithParams:params];
        
#pragma mark ---------收藏试题--------------------
  
        
        SGParameter *parameter  = [[SGParameter alloc] init];
        parameter.body = @{@"question_id":self.model.ques_id ? : @"",
                           @"status":@"1"
                           };
        
        [SGHttpTool POST:[NSString stringWithFormat:@"%@g=Client&m=Question&a=collectQuestion",HTTPP] parameter:parameter sucess:^(id responseObject) {
            NSLog(@"%@",responseObject);
            NSDictionary *dic = responseObject;
            
            if ([dic[@"status"] intValue] == 200) {
                
             [MBProgressHUD showTextOnly:kKeyWindow message:dic[@"msg"]];
                
            }else{
               [MBProgressHUD showTextOnly:kKeyWindow message:dic[@"msg"]];
            }
            
        } failure:^(NSError *error) {
            NSLog(@"%@",error);
            
        }];
        
        
    }];
}

@end
